#!/bin/bash

DOCKER_NAME=houxin-gateway
DOCKER_FILE=Dockerfile
echo "DOCKER_NAME is ${DOCKER_NAME}"

DOCKER_IMAGE=`/usr/bin/docker images | grep ${DOCKER_NAME} | awk -F ' ' '{print $3}'`
if [ -n "${DOCKER_IMAGE}" ]; then
        # check docker container
        for dc in `/usr/bin/docker ps -a | grep ${DOCKER_NAME}  | awk -F " " '{print $1}'`
        do
                echo "Stop container: ${dc}"
                /usr/bin/docker stop ${dc}
                # delete while docker container was exists
                echo "##Delete exists Container_Id: "${dc}
                /usr/bin/docker rm ${dc}
        done

        # delete while docker image was exists
        echo "##Delete exists Image: "${DOCKER_IMAGE}
        /usr/bin/docker rmi ${DOCKER_IMAGE}
fi
echo "****delete finish*****"

echo "**Init dockerfile start***"

 /usr/bin/docker build  -f ${DOCKER_FILE}  -t ${DOCKER_NAME}  .

/usr/bin/docker run -e TZ="Asia/Shanghai" --privileged  \
-itd -h ${DOCKER_NAME}.com --name ${DOCKER_NAME} \
-v /opt/module/houxin/houxin-gateway/logs:/usr/lib/java/logs/houxin-gateway  \
-p 9999:9999 --network=houxin-net  --ip 172.18.1.5  ${DOCKER_NAME}
